package com.adms.controller;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.adms.domain.Grid;
import com.adms.service.GridService;

@RequestMapping("grid")
@RestController
public class GridController {

	@Autowired
	private GridService gridService;
	
	@GetMapping("{gridId}")
	public Object getByGridId(@PathVariable("gridId") Integer gridId) {
		return gridService.getByGridId(gridId);
	}
	
	@GetMapping("getWithRelativeUsers")
	public Object getByGridIdWithRelativeUsers(@RequestParam("gridId") Integer gridId) {
		return gridService.getByGridIdWithRelativeUsers(gridId);
	}
	
	@GetMapping
	public Object list(Grid grid,String timeField,Date start,Date end,String orderByClause,String key,
			@RequestParam(defaultValue = "1") Integer pageNum,
			@RequestParam(defaultValue = "5") Integer pageSize,
			@RequestParam(defaultValue = "5") Integer navigatePages) {
		return gridService.list(grid,timeField,start,end,orderByClause,key,pageNum,pageSize,navigatePages);
	}
	
	@PostMapping("create")
	public Object create(Grid grid,int[] gridUserIds,Integer defaultGridUserId) {
		return gridService.create(grid,gridUserIds,defaultGridUserId);
	}
	
	@PostMapping("update")
	public Object update(Grid grid,int[] gridUserIds,Integer defaultGridUserId) {
		return gridService.update(grid,gridUserIds,defaultGridUserId);
	}
	
	@PostMapping("delete")
	public Object delete(Integer[] gridIds) {
		return gridService.delete(gridIds);
	}
	
}
